/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
package fr.jade.util.log;

import java.util.Vector;

import fr.jade.util.log.handler.FileHandler;
import fr.jade.util.log.handler.Handler;
import fr.jade.util.log.handler.TerminalHandler;

/**
 * @author Sylvain Sicard
 * 
 */
public class Logger {

  static boolean log = true;
  
  static Logger l;
  
  static{
    l = new Logger();
  }
  
  private Vector<Handler> handlers;  

  public Logger() {
    handlers = new Vector<Handler>();

    Handler h1 = new TerminalHandler();
    h1.start();
//    Handler h2 = new FileHandler();
//    h2.start();

    handlers.add(h1);
//    handlers.add(h2);
  }

  public static void println(boolean level, String s) {
    if (level) {
      l.log(s);
    }
  }

  public static void println(boolean level, Exception s) {
    if (level) {
      l.log(s);
    }
  }

  public synchronized void log(String s) {
    for (Handler h : handlers)
      h.log(s);
  }
  
  public synchronized void log(Exception e) {
    if(e!=null)
    for (Handler h : handlers){
      e.printStackTrace(h.getPrintStream());
    }
  }

  
  public static synchronized void println(String s) {
    l.log(s);
  }
  
  public static synchronized void println(Exception e) {
    l.log(e);
  }
}
